﻿package com.cenfun.ui{
	import fl.controls.*;
	import fl.controls.listClasses.*;
	import fl.core.*;
	import flash.events.*;
	import flash.text.*;
	import flash.display.*;
	import flash.geom.*;
	public class TC extends CellRenderer {
		private var ld:ListData;
		private var tn:TN;
		public function TC():void {
			super();
			this.addEventListener(MouseEvent.CLICK, clickHandler);
		}
		//单击图标
		private function clickHandler(e:MouseEvent):void {
			if (icon) {
				var rect:Rectangle = new Rectangle(icon.x, icon.y, icon.width, icon.height);
				if (rect.contains(mouseX, mouseY)) {
					e.stopImmediatePropagation();
					tn.toggle();
				}
			}
		}
		override public function set listData(_listData:ListData):void {
			ld = _listData;
			if (tn.nodeType == TD.NODE_L) {
				if (tn.opened) {
					setStyle("icon", new IconOpened());
				} else {
					setStyle("icon", new IconClosed());
				}
			} else {
				setStyle("icon", new IconMedia());
			}
			//选择项加亮
			if (Tree.play_item == tn) {
				setStyle("textFormat", Tree.format_on);
			} else {
				setStyle("textFormat", Tree.format);
			}
		}
		override public function get listData():ListData {
			return ld;
		}
		override public function set data(_data:Object):void {
			tn = _data as TN;
			//
			var str:String = "";
			//错误
			
			//行标记
			str += tn.label || tn.title || tn[null] || tn['src'] || "";
			//输出
			label = str;
			tn.label = str;
		}
		override public function get data():Object {
			return tn;
		}


		//================================================================================================
		//添加缩进距离
		override protected function drawLayout():void {
			super.drawLayout();
			if (icon != null) {
				var marginLeft:int = (tn.level - 1) * TR.indent;
				icon.x += marginLeft;
				textField.x += marginLeft;
			}
		}

	}
}